﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace paintapplication
{
    public partial class Form1 : Form
    {
       
        
        private Point m_old;
        private Point m_cur;
        private int shape;
        private Color color;
        private int withd;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            m_old = e.Location;
        }

      

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            m_cur = e.Location;
            Invalidate();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
            color = Color.Black;
            withd = 1;
            shape = 0;
            
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Pen pen = new Pen(color, withd);
            int x = (m_old.X > m_cur.X) ? m_cur.X : m_old.X;
            int y = (m_old.Y > m_cur.Y) ? m_cur.Y : m_old.Y;
            int w = Math.Abs(m_old.X - m_cur.X);
            int h = Math.Abs(m_old.Y - m_cur.Y);
                switch (shape) { 
                       
                    case 0:
                        
                        e.Graphics.DrawLine(pen, m_old,m_cur);
                        break;
                    case 1:
                        e.Graphics.DrawRectangle(pen, x,y,w,h);
                        break;
                    case 2:
                        e.Graphics.DrawEllipse(pen,x,y,w,h);
                        break;
                
                
              
            
            
            
            }
        }

        private void lineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            shape = 0;
            this.rectageToolStripMenuItem.Checked = false;
            this.elipseToolStripMenuItem.Checked = false;
        }

        private void rectageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            shape = 1;
            this.elipseToolStripMenuItem.Checked = false;
            this.lineToolStripMenuItem.Checked = false;
        }

        private void elipseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            shape = 2;
            this.lineToolStripMenuItem.Checked = false;
            this.rectageToolStripMenuItem.Checked = false;
        }

        private void redToolStripMenuItem_Click(object sender, EventArgs e)
        {
            color = Color.Red;
            this.greenToolStripMenuItem.Checked = false;
            this.blueToolStripMenuItem.Checked = false;
        }

        private void greenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            color = Color.Green;
            this.redToolStripMenuItem.Checked = false;
            this.blueToolStripMenuItem.Checked = false;


        }

        private void blueToolStripMenuItem_Click(object sender, EventArgs e)
        {
            color = Color.Blue;
            this.redToolStripMenuItem.Checked = false;
            this.greenToolStripMenuItem.Checked = false;

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
